﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.KEYW;
using AjaxPro;

namespace Mang24k99.Business.KEYW
{
    public static  class BKeyWords
    {
        /// <summary>
        /// 根据输入字符串（拼音助记码or代码or名称）选择向前匹配的前10条数据
        /// </summary>
        /// <param name="spell"></param>
        /// <returns></returns>
        public static MKtKeywNewstraword[] SelectByInput(string strInput)
        {
            return (MKtKeywNewstraword[])MKtKeywNewstraword.SelectByInput(strInput);
        }

        /// <summary>
        /// 创建一条MKtKeywWords记录
        /// </summary>
        /// <param name="keywords"></param>
        public static void Create(MKtKeywWords keywords)
        {
            MKtKeywWords.Create(keywords);
        }
        /// <summary>
        /// 创建一条MKtKeywFixwords记录
        /// </summary>
        /// <param name="fixword"></param>
        public static void CreateFix(MKtKeywFixwords fixword)
        {
            MKtKeywFixwords.Create(fixword);
        }
        /// <summary>
        /// 根据匹配的MKtKeywNewstraword数据生成Table
        /// </summary>
        /// <param name="Spell"></param>
        /// <param name="objtxt"></param>
        /// <param name="objtxtSource"></param>
        /// <returns></returns>
        [AjaxMethod]
        public   static string GetSearchStockResult(string Spell, string objtxt, string objtxtSource)
        {
            StringBuilder stringBuilderReturn = new StringBuilder();

            stringBuilderReturn.Append("<table id=\"searchTable\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" align=\"center\" bordercolor=\"#BED6A6\"");
            stringBuilderReturn.Append("style=\"border-collapse: collapse\">");
            try
            {
                MKtKeywNewstraword[] starword = (MKtKeywNewstraword[])MKtKeywNewstraword.SelectByInput(Spell);
                for (int i = 0; i < starword.Length; i++)
                {
                    stringBuilderReturn.Append("<tr>");
                    stringBuilderReturn.Append("<td class=\"tb_txt2\"  nowrap=\"nowrap\" style=\"cursor:pointer;\" title=\"" + starword[i].WordNO + "\" onclick=\"SearchStockHide('" + objtxt + "',this.innerHTML,'" + objtxtSource + "',this.title)\">");
                    stringBuilderReturn.Append("" + starword[i].WordName + "</td>");
                    stringBuilderReturn.Append("</tr>");
                }
            }
            catch (System.Exception e)
            {

            }
            stringBuilderReturn.Append("</table>");
            return stringBuilderReturn.ToString();
        }
   
        /// <summary>
        /// 判断某关键词是否有效（有效条件：IsValidate=1,IS_LEAF=1）
        /// </summary>
        /// <param name="Keyword"></param>
        /// <returns></returns>
        public static bool IsValidate(int Keyword)
        {
            return MKtKeywNewstraword.Validate(Keyword);
        }
    }
}
